import numpy as np
import scipy.stats as st


def calculate_confidence_interval(data, method='t'):
    if method == 't':
        a, b = st.t.interval(confidence=0.97, df=len(data) - 1, loc=np.mean(data), scale=st.sem(data))
        return a, b
    elif method == 'normal':
        c, d = st.norm.interval(confidence=0.97, loc=np.mean(data), scale=st.sem(data))
        return c, d
    else:
        raise ValueError("Invalid method. Please choose 't' for t-distribution or 'normal' for normal distribution.")


# # Define sample data
# data = [88, 80, 78, 92, 95, 88, 86, 83]
#
# # Calculate 95% confidence interval for population mean weight using t-distribution
# a_t, b_t = calculate_confidence_interval(data, method='t')
#
# # Calculate 95% confidence interval for population mean weight using normal distribution
# c_norm, d_norm = calculate_confidence_interval(data, method='normal')
#
# print("T-Distribution Interval:", a_t, b_t)
# print("Normal Distribution Interval:", c_norm, d_norm)

'''
source训练集合比如花卉数据，
Dclose1型表示是数据集中没参与训练的花卉数据，
Dclose2型表示不是数据集中的花卉数据（有可能这一些花卉数据的花卉类别就没在训练中声明），
Ddistance与训练数据结构相差特别大的数据集比如宠物

https://www.zhihu.com/question/300017993
'''